<template>
  <!-- VIP领取记录 -->
  <div class="app-container">
    <div class="app-wrap">
      <search-table ref="table" :table-loading="listLoading" :table-data="vipDataList" @query="getVipRecordList(true)" @reset="refresh">
        <template v-slot:row>
          <el-form-item class="marginR20">
            <el-select v-model="listQuery.condition" filterable placeholder="请选择类型">
              <el-option :label="item.label" :value="item.value" v-for="(item, index) in conditionData" :key="index"></el-option>
            </el-select>
            <el-input type="text" v-model="listQuery.inputValue" clearable placeholder="请输入数值"  />
          </el-form-item>
          <el-form-item  label="日期时间:" label-width="80px">
            <el-date-picker is-range v-model="listQuery.dateTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" 
            end-placeholder="结束日期" class="full-width-input time-box" :default-time="['00:00:00', '23:59:59']" :clearable="false"></el-date-picker>
          </el-form-item>
          <el-form-item label="领取类型:" label-width="90px">
            <el-select v-model="listQuery.type" filterable placeholder="请选择类型">
              <el-option :label="item.label" :value="item.value" v-for="(item, index) in statusData" :key="index"></el-option>
            </el-select>
          </el-form-item>
        </template>
        <template v-slot:actions>
          <el-button type="info" size="mini" icon="el-icon-refresh" @click="getVipRecordList">刷新</el-button>
        </template>
        <template>
          <el-table-column align="center" prop="user_id" label="用户ID" width="120" />
          <el-table-column align="center" prop="nick_name" label="用户昵称" show-overflow-tooltip/>
          <el-table-column prop="agent_id" label="渠道名" align="center" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-show="scope.row.agent_id">【{{scope.row.agent_id}}】{{ $public.channelLabel(scope.row.agent_id) }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="vip_level" label="VIP等级" width="150"/>
          <el-table-column align="center" prop="amount" label="领取的金额"  width="240"/>
          <el-table-column align="center" prop="receive_type" label="领取类型" width="200">
            <template slot-scope="scope">
              {{ downType(scope.row.receive_type) }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="time" label="领取时间"/>
        </template>
        <template v-slot:footer>
          <pagination  :total="currentTotal" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="getVipRecordList" />
        </template>
      </search-table>
    </div>
  </div>
</template>

<script>
import { throttle } from "@/utils/index";
import { 
  getVipRecord
 } from "@/api/game";
import SearchTable from "@/components/SearchTable";
export default {
  name: "vipRecord",
  components: {
    SearchTable,
  },
  data () {
    return {
      vipDataList: [],
      conditionData:[{
        label:'用户ID',
        value:'user_id'
      },{
        label:'渠道名称',
        value:'agent_id'
      }],
      statusData:[{
        label:'全部',
        value:1
      },{
        label:'每月礼金',
        value:2
      },{
        label:'升级彩金',
        value:3
      },{
        label:'周购礼包',
        value:4
      }],
      checkedItem: null,
      listLoading: false,
      isShowDetails: false,
      currentTotal: 0,
      listQuery: {
        page: 1,
        size: 50,
        condition:'user_id',
        inputValue:'',
        type:1,
        dateTime: [this.$public.getDateWeek('s',0)+' 00:00:00',this.$public.getDateWeek('e',0)+' 23:59:59'],
        start_time: '',
        end_time: '',
      },
    };
  },
  created () {
    this.getVipRecordList();
  },
  methods: {
    // 获取领取记录
    async getVipRecordList (query) {
      let that = this,params=that.listQuery;
      if(query && !query.page){
        params.page=1
        params.size=50
      }
      that.vipDataList = [];
      that.checkedItem = null;
      that.listLoading = true;
      // 用户ID
      if(params.condition=='user_id'){
        params.user_id=params.inputValue
        params.agent_id=''
      }
      // 渠道名称
      if(params.condition=='agent_id'){
        params.agent_id=params.inputValue
        params.user_id=''
      }
      if (params.dateTime && params.dateTime[0] && params.dateTime[1]) {
        params.start_time = that.$public.standardDate(params.dateTime[0])
        params.end_time = that.$public.standardDate(params.dateTime[1])
      }else{
        params.start_time = ''
        params.end_time = ''
      }
      const response = await getVipRecord(params)
      if (response.code==1) {
        if (response.data.list) {
          response.data.list.forEach((item) => {
            item.isChecked = false;
            item.amount=that.$public.mathNumberDivideWan(item.amount)
          });
          that.currentTotal = response.data.total;
          that.vipDataList = response.data.list;
        }
      }else{
        that.$message.error(response.msg)
      }
      that.listLoading = false;
    },
    // 领取类型
    downType(cellValue){
      return (this.statusData.find((item) => item.value === cellValue)?.label || "-");
    },
    // 刷新
    refresh: throttle(function () {
      this.listQuery = {
        page: 1,
        size: 50,
        condition:'user_id',
        inputValue:'',
        dateTime: [this.$public.getDateWeek('s',0)+' 00:00:00',this.$public.getDateWeek('e',0)+' 23:59:59'],
        start_time: '',
        end_time: '',
      };
      this.getVipRecordList();
    }, 2000),
  },
};
</script>

<style lang="scss" scoped></style>
